package com.czz.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czz.common.exception.CustomerException;
import com.czz.common.exception.ResultCodeEnum;
import com.czz.ucenter.entity.Teacher;
import com.czz.ucenter.mapper.TeacherMapper;
import com.czz.ucenter.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @ClassName: TeacherService
 * @Author Czz
 * @Date 2019/12/23
 * @Time 16:43
 **/
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    TeacherMapper teacherMapper;

    @Override
    public Teacher getTeacherByUserId(String user_id) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<Teacher>();
        //根据用户id查询讲师
        queryWrapper.eq("user_id",user_id);

        Teacher teacher = teacherMapper.selectOne(queryWrapper);

        if (teacher.getStatus().equals(1)){
            throw new CustomerException(ResultCodeEnum.USER_BAN);
        }

        if (ObjectUtils.isEmpty(teacher)){
            return null;
        }
        return teacher;
    }
}
